﻿/// Write a method that checks if the element at given position in given array of integers
/// is bigger than its two neighbors (when such exist).


using System;

namespace c_sh_II_lek_3
{
    class Zad4
    {
        static void Main()
        {
            int[] arr = { 1, 3, 5, 9, 7, 2};
            Console.WriteLine( IsBiggerThenNeighbors(arr, 2) ); 
           
        }

        public static bool IsBiggerThenNeighbors(int[] array, int number)
        {
            bool isBiggerThenNeighbors = false;

            for (int i = 0; i < array.Length; i++)
            {
                if (array[i] == number)
                {
                    if (CanGo(array.Length, i) && array[i+1] < number && array[i-1] < number)
                    {
                        isBiggerThenNeighbors = true;
                    }
                    else
                    {
                        isBiggerThenNeighbors = false;
                    }
                }
            }
            return isBiggerThenNeighbors;
        }

        static bool CanGo(int arrayLength, int currentIndex)
        {
            if (currentIndex < 1 || currentIndex > arrayLength - 2)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}
